// components/input/input.ts
Component({
  /**
   * 组件的属性列表
   */
  properties: {
    elementType: {
      type: String,
    },
    bgColor: {
      type: String,
      default: '#1E1E27'
    },
    width: {
      type: Number
    },
    height: {
      type: Number
    },
    errorMessage: {
      type: String
    },
    placeholder: {
      type: String
    },
    borderRadiusSize: {
      type: Number
    }
  },

  /**
   * 组件的初始数据
   */
  data: {
    isActive: false,
    isError: false,
    isPassWord: false,
    eleType: null,
    value: null
  },

  pageLifetimes: {
    // 页面被展示
    show: function () {
      this.setData({
        eleType: this.properties.elementType
      })
    },
  },

  /**
   * 组件的方法列表
   */
  methods: {
    onIsPassWordFn() {
      this.setData({
        isPassWord: !this.properties.isPassWord,
        eleType: this.properties.isPassWord ? 'password' : 'text',
        value: this.properties.value
      })
    },
    setInputData(msg: any) {
      this.setData({
        value: msg.detail.value
      })

      this.triggerEvent("callBack", msg.detail.value);
    },
    // 聚焦
    inputFocusFn() {
      this.setData({
        isActive: true
      })
    },

    // 失焦
    inputBlurFn() {
      this.setData({
        isActive: false
      })
    }
  }
})
